package csci318.sfm.g3.controller;

import csci318.sfm.g3.fetest.Csci318;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.ComboBox;
import javafx.scene.text.Text;

public class LoginController implements Initializable {

    @FXML
    private TextField userId;
    @FXML
    private PasswordField password;
    @FXML
    private Text errorMessage;
    @FXML
    private ComboBox<String> accountType;

    @FXML
    protected void processLogin() {
        if (accountType.getValue().equals("Admin")) {
            if (!Csci318.getInstance().adminLogging(userId.getText(), password.getText())) {
                errorMessage.setText("Invalid Password!");
            } else {
                errorMessage.setText("Logging In!");
            }
        } else if (accountType.getValue().equals("Staff")) {
            if (!Csci318.getInstance().staffLogging(userId.getText(), password.getText())) {
                errorMessage.setText("Invalid Password!");
            } else {
                errorMessage.setText("Logging In!");
            }
        } else if (accountType.getValue().equals("User")) {
            if (!Csci318.getInstance().userLogging(userId.getText(), password.getText())) {
                errorMessage.setText("Invalid Password!");
            } else {
                errorMessage.setText("Logging In!");
            }
        } else {
            errorMessage.setText("Invalid Account Type!");
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        userId.setPromptText("User Name");
        password.setPromptText("Password");
    }
}